//导入路由组件
import {Router, Route, Switch, Redirect} from 'react-router-dom'
//导入页面组件
import Login from '@/pages/Login'
import Layout from '@/pages/Layout'
import './App.scss';
import ProfileEdit from '@/pages/Profile/Edit'
import PrivateRoute from './components/PrivateRoute';
import history from './utils/history';
import Chat from '@/pages/Profile/Chat'
import Article from '@/pages/Article'
import SearchPage from '@/pages/Search'
import Result from './pages/Search/Result';

function App() {
  return (
    <Router history={history}>
      <div className="app">
        <Switch>
          {/* 写法一：使用Route render属性 */}
          {/* <Route exact path='/' render={() => (
            <Redirect to='/home' />
          )}></Route> */}

          {/* 写法一：如果当前url是/ 跳转到 /home */}
          <Redirect exact from='/' to='/home'/>
          <Route path='/login'>
            <Login></Login>
          </Route>
          <Route path='/home'>
            <Layout></Layout>
          </Route>
          <PrivateRoute
            path='/profile/edit'
          >
            <ProfileEdit></ProfileEdit>
          </PrivateRoute>
          <PrivateRoute path='/chat'>
            <Chat></Chat>
          </PrivateRoute>
          <Route path={'/article/:id'}>
            <Article></Article>
          </Route>
          <Route exact path='/search'>
            <SearchPage></SearchPage>
          </Route>
          <Route path='/search/result'>
            <Result></Result>
          </Route>
        </Switch>
      </div>
    </Router>
  );
}

export default App;
